<template>
  <div class="wrapper">
    <x-tabbar :tab-titles="tabTitles" 
        :tab-styles="tabStyles"
        title-type="iconFont" >
    <!-- 首页 -->
    <div class="item-container" :style="contentStyle">
      <home ref="homePage"></home>
    </div>
    <!-- 兑换 -->
    <div class="item-container" :style="contentStyle">
      
    </div>
    <!-- 到店 -->
    <div class="item-container" :style="contentStyle">
      
    </div>
    <!-- 购物车 -->
    <div class="item-container" :style="contentStyle">
      
    </div>
    <!-- 我的 -->
    <div class="item-container" :style="contentStyle">
      <my ref="myPage"></my>
    </div>
  </x-tabbar>
  </div>
  
</template>

<script>
import Utils from "./common/js/utils";
import asCore from "./common/js/core";
import config from "./configs/tbconfig";
var modal = weex.requireModule("modal");
const navigator = weex.requireModule("navigator");
const loginBroad = new BroadcastChannel("login");
const storage = weex.requireModule('storage'); 
export default {
  components: {
    "x-tabbar": require("./common/component/tabbar.vue"),
    "home": require("./tailor/index/home.vue"),
    "my": require("./tailor/index/my.vue")
  },
  beforeCreate() {
    var globalEvent = weex.requireModule("globalEvent");
    globalEvent.addEventListener("onPageInit", function(e) {
      //const nav = weex.requireModule("navbar");
      //nav.setStatusBarStyle("white");
      navigator.addBackGestureSelfControl();
    });
    /* 判断是否登录过和是否超时(超时将自动从登) */
    asCore.getToken(token =>{
      if (!token) {
        navigator.push(asCore.localpath + "login.js");
      }else {
        //this.$refs.shopPage.getCarData();
       //this.$refs.storePage.getData();
        this.$refs.myPage.getInfo();
      }
    });
    /* 双击退出程序 */
    const page  = weex.requireModule("page");
    page.doubleBack();
    /* 登录之间进行通信的隧道 */
    loginBroad.onmessage = function(event) {
       var data = event.data;
       if(data.success == 1){
         page.reload();
       }
    };
  },
  created() {
    Utils.initIconFont();
    const tabPageHeight = Utils.env.getPageHeight();
    const { tabStyles } = this;
    this.contentStyle = { height: tabPageHeight + 25 + "px" };
  },
  data() {
    return {
      tabTitles: config.tabIconFontTitles,
      tabStyles: config.tabIconFontStyles
    };
  },
  methods: {
  }
};
</script>
<style scoped>
.wrapper {
  
}
.item-container {
  flex: 1;
  width: 750px;
  background-color: #dedfe1;
}
</style>
